<# # It is recommended to test the script on a local machine for its purpose and effects. # ManageEngine Endpoint Central will not be responsible for any # damage/loss to the data/setup based on the behavior of the script. # Description: Script is designed to set the Primary & secondary DNS to all the network adapters available in the machine # Configuration Type - COMPUTER # Arguments - "Primary IP address" "Secondary IP Address" # Example - "192.21.06.99" "192.07.02.00" #> # Get all network adapters $networkAdapters = Get-NetIPConfiguration | Select -ExpandProperty InterfaceAlias # Define the primary and secondary IP addresses from the arguments $prIp = $args[0] $secIp = $args[1] if (-not $prIp -or -not $secIp) { Write-Host "Please provide both primary and secondary DNS IP addresses." exit } $count = 0 # Loop through each network adapter and set the DNS server addresses foreach ($adapter in $networkAdapters) { try { Set-DNSClientServerAddress -InterfaceAlias $adapter -ServerAddresses ($prIp, $secIp) -ErrorAction Stop Write-Host "Updated DNS for adapter: $adapter" $count++ } catch { Write-Host "Failed to update DNS for adapter: $adapter. Error: $_" } } if ($count -eq 0) { Write-Host "No network adapters found or no DNS values changed." } else { Write-Host "$count network adapter(s) updated with new DNS server addresses." }